package com.itheima.zuoye.zuoye4;

import java.time.LocalDateTime;

class    Goods {
    public static final LocalDateTime START = LocalDateTime.of(2025, 7, 11, 21, 0); // 10:00
    public static final LocalDateTime END = LocalDateTime.of(2025, 7, 11, 22, 0); // 12:00

    private String name;
    private int count;          // 剩余库存

    public Goods(String name, int count) {
        this.name = name;
        this.count = count;
    }

    public String getName() {
        return name;
    }

    public int getStock() {
        return count;
    }

    public String secKill() {
        LocalDateTime now = LocalDateTime.now();
        if (now.isBefore(START)) {
            return "秒杀尚未开始！";
        }
        if (now.isAfter(END)) {
            return "秒杀已结束！";
        }
        if (count <= 0) {
            return "【" + name + "】已售罄！";
        }
        count--;
        return "恭喜！秒杀【" + name + "】成功，剩余库存：" + count;
    }

    @Override
    public String toString() {
        return "商品{商品名称='" + name + "', 库存数量=" + count + "}";
    }
}


